home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / plot.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  14.6 KB  |  590 lines

  1. /*
  2.  * $Id: plot.h,v 1.5 1993/05/18 03:55:52 davis Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - plot.h */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * Send your comments or suggestions to 
  35.  *  info-gnuplot@dartmouth.edu.
  36.  * This is a mailing list; to join it send a note to 
  37.  *  info-gnuplot-request@dartmouth.edu.  
  38.  * Send bug reports to
  39.  *  bug-gnuplot@dartmouth.edu.
  40.  */
  41.  
  42. #define PROGRAM "G N U P L O T"
  43. #define PROMPT "gnuplot> "
  44. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  45. #define SHELL "NewShell"
  46. #else /* AMIGA */
  47. #ifdef ATARI
  48. #define SHELL "gulam.prg"
  49. #else /* ATARI */
  50. #ifdef OS2
  51. #define SHELL "c:\\cmd.exe"
  52. #else /*OS2 */
  53. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  54. #endif /*OS2 */
  55. #endif /* ATARI */
  56. #endif /* AMIGA  */
  57.  
  58. #if defined(__unix__) && !defined(unix)
  59. #define unix
  60. #endif
  61.  
  62. #define SAMPLES 100        /* default number of samples for a plot */
  63. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  64. #define ZERO    1e-8        /* default for 'zero' set option */
  65.  
  66. #ifndef TERM
  67. /* default terminal is "unknown"; but see init_terminal */
  68. #define TERM "unknown"
  69. #endif
  70.  
  71. #define TRUE 1
  72. #define FALSE 0
  73.  
  74.  
  75. #define Pi 3.141592653589793
  76. #define DEG2RAD (Pi / 180.0)
  77.  
  78.  
  79. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  80. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  81.  
  82. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  83. #define MAX_TOKENS 400
  84. #define MAX_ID_LEN 50        /* max length of an identifier */
  85.  
  86.  
  87. #define MAX_AT_LEN 150        /* max number of entries in action table */
  88. #define STACK_DEPTH 100
  89. #define NO_CARET (-1)
  90.  
  91. #ifdef MSDOS
  92. #define MAX_NUM_VAR    3    /* Ploting projection of func. of max. five vars. */
  93. #else
  94. #define MAX_NUM_VAR    5    /* Ploting projection of func. of max. five vars. */
  95. #endif
  96.  
  97. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  98. #define MAP3D_SPHERICAL        1
  99. #define MAP3D_CYLINDRICAL    2
  100.  
  101. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  102. #define CONTOUR_BASE    1
  103. #define CONTOUR_SRF    2
  104. #define CONTOUR_BOTH    3
  105.  
  106. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  107. #define CONTOUR_KIND_CUBIC_SPL    1
  108. #define CONTOUR_KIND_BSPLINE    2
  109.  
  110. #define LEVELS_AUTO            0        /* How contour levels are set */
  111. #define LEVELS_INCREMENTAL    1        /* user specified start & incremnet */
  112. #define LEVELS_DISCRETE        2        /* user specified discrete levels */
  113. #define MAX_DISCRETE_LEVELS   30
  114.  
  115. #define ANGLES_RADIANS    0
  116. #define ANGLES_DEGREES    1
  117.  
  118.  
  119. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  120. #define OS "Amiga "
  121. #endif
  122.  
  123. #ifdef OS2
  124. #ifdef unix
  125. #undef unix    /* GCC might declare this */
  126. #define OS "OS/2"
  127. #endif
  128. #endif  /* OS2 */
  129.  
  130. #ifdef vms
  131. #define OS "VMS "
  132. #endif
  133.  
  134.  
  135. #ifdef unix
  136. #define OS "unix "
  137. #endif
  138.  
  139.  
  140. #ifdef _WINDOWS
  141. #define _Windows
  142. #endif
  143.  
  144. #ifdef DOS386
  145. #define OS "DOS 386 "
  146. #endif
  147. #ifdef _Windows
  148. #define OS "MS-Windows "
  149. #else
  150. #ifdef MSDOS
  151. #ifdef unix    /* __EMX__ and DJGPP may set this */
  152. #undef OS
  153. #undef unix
  154. #endif
  155. #define OS "MS-DOS "
  156. #endif
  157. #endif
  158.  
  159.  
  160. #ifdef ATARI
  161. #define OS "TOS "
  162. #endif
  163.  
  164. #ifndef OS
  165. #define OS ""
  166. #endif
  167.  
  168.  
  169. /* To access curves larger than 64k, MSDOS needs to use huge pointers */
  170. #if (defined(__TURBOC__) && defined(MSDOS)) || (defined(_Windows) && !defined(WIN32))
  171. #define GPHUGE huge
  172. #define GPFAR far
  173. #else
  174. #define GPHUGE
  175. #define GPFAR
  176. #endif
  177.  
  178.  
  179. /*
  180.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  181.  * numbers. This flag indicates very large numbers. It doesn't have to 
  182.  * be the absolutely biggest number on the machine.  
  183.  * If your machine doesn't have HUGE, or float.h,
  184.  * define VERYLARGE here. 
  185.  *
  186.  * This is a mess.  If someone figures out how to clean this up, please
  187.  *    diff -c  of your fixes
  188.  *
  189.  *
  190.  * example:
  191. #define VERYLARGE 1e37
  192.  */
  193.  
  194. #ifdef ATARI
  195. #include <stdlib.h>        /* Prototyping used !! 'size_t' */
  196. #include <stdio.h>
  197. #include <string.h>
  198. #include <math.h>
  199. #define VERYLARGE    HUGE_VAL
  200. #else  /* not ATARI */
  201. #if defined(MSDOS) || defined(_Windows)
  202. #include <float.h>
  203. #define VERYLARGE (FLT_MAX/2 -1)
  204. #else  /* not MSDOS || _Windows */
  205. #if defined( vms ) || defined( _CRAY ) || defined( NEXT ) || defined(__osf__) || defined( OS2 ) || defined(__EMX__) || defined( DOS386) || defined(KSR)
  206. #include <float.h>
  207. #if defined ( NEXT )  /* bug in NeXT OS 2.0 */ && !defined (NEXTFE) /*not 3.0*/
  208. #if defined ( DBL_MAX)
  209. #undef DBL_MAX
  210. #endif
  211. #define DBL_MAX 1.7976931348623157e+308 
  212. #undef HUGE
  213. #define HUGE    DBL_MAX
  214. #undef HUGE_VAL
  215. #define HUGE_VAL DBL_MAX
  216. #endif /* not NEXT but CRAY, VMS or OSF */
  217. #define VERYLARGE (DBL_MAX/2 -1)
  218. #else  /* not vms, CRAY, NEXT, OS/2 or OSF */
  219. #ifdef AMIGA_AC_5
  220. #include <math.h>
  221. #define VERYLARGE (HUGE/2 -1)
  222. #else /* not AMIGA_AC_5 */
  223. #ifdef AMIGA_SC_6_1
  224. #include <float.h>
  225. #ifndef HUGE
  226. #define HUGE DBL_MAX
  227. #endif
  228. #define VERYLARGE (HUGE/2 -1)
  229. #else /* !AMIGA_SC_6_1 */
  230. /* #include <float.h> */
  231. #ifdef ISC22
  232. #include <float.h>
  233. #ifndef HUGE
  234. #define HUGE DBL_MAX
  235. #endif
  236. #endif /* ISC22 */
  237. /* This is the default */
  238. #ifndef HUGE
  239. #define HUGE DBL_MAX
  240. #endif
  241. #define VERYLARGE (HUGE/2 -1)
  242. /* default */
  243. #endif /* !AMIGA_SC_6_1 */
  244. #endif /* !AMIGA_AC_5 */
  245. #endif /* !VMS !CRAY !NEXT */
  246. #endif /* !MSDOS || !_Windows */
  247. #endif /* !ATARI */
  248.  
  249. #ifdef AMIGA_SC_6_1
  250. /* Get function prototypes */
  251. #include <stdio.h>
  252. #include <stdlib.h>
  253. #include <string.h>
  254. #include <math.h>
  255. #endif /* AMIGA_SC_6_1 */
  256.  
  257. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  258.  
  259. #ifdef vms
  260.  
  261.  
  262. #define is_comment(c) ((c) == '#' || (c) == '!')
  263. #define is_system(c) ((c) == '$')
  264.  
  265.  
  266. #else /* vms */
  267.  
  268. #define is_comment(c) ((c) == '#')
  269. #define is_system(c) ((c) == '!')
  270.  
  271. #endif /* vms */
  272.  
  273. /* If you don't have vfork, then undefine this */
  274. #if defined(NOVFORK) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  275. # undef VFORK
  276. #else
  277. # ifdef unix
  278. #  define VFORK
  279. # endif
  280. #endif
  281.  
  282. /* 
  283.  * memcpy() comes by many names. The default is now to assume bcopy, 
  284.  * since it is the most common case. Define 
  285.  *  MEMCPY to use memcpy(), 
  286.  *  vms to use the vms function,
  287.  *  NOCOPY to use a handwritten version in parse.c
  288.  */
  289. #ifdef vms
  290. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  291. #else
  292. # if defined(MEMCPY) || defined(MSDOS) || defined (ATARI) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  293.    /* use memcpy directly */
  294. # else 
  295. #  ifdef NOCOPY
  296.     /* use the handwritten memcpy in parse.c */
  297. #  else
  298.     /* assume bcopy is in use */
  299. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  300. #  endif /* NOCOPY */
  301. # endif /* MEMCPY || MSDOS */
  302. #endif /* vms */
  303.  
  304. /*
  305.  * In case you have MEMSET instead of BZERO. If you have something 
  306.  * else, define bzero to that something.
  307.  */
  308. #if defined(MEMSET) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  309. #define bzero(dest,len)  (void)(memset(dest, 0, len))
  310. #endif /* MEMSET || MSDOS */
  311.  
  312. #define top_of_stack stack[s_p]
  313.  
  314. typedef int TBOOLEAN;
  315.  
  316. #ifdef __ZTC__
  317. typedef int (*FUNC_PTR)(...);
  318. #else
  319. typedef int (*FUNC_PTR)();
  320. #endif
  321.  
  322. enum operators {
  323.     PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD, CALL, CALLN, LNOT, BNOT, UMINUS,
  324.     LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
  325.     DIV, MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  326. };
  327.  
  328.  
  329. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  330.  
  331.  
  332. enum DATA_TYPES {
  333.     INTGR, CMPLX
  334. };
  335.  
  336.  
  337. enum PLOT_TYPE {
  338.     FUNC, DATA, FUNC3D, DATA3D
  339. };
  340.  
  341. /*XXX - JG */
  342. enum PLOT_STYLE {
  343.     LINES, POINTSTYLE, IMPULSES, LINESPOINTS, DOTS, ERRORBARS, BOXES, BOXERROR, STEPS
  344. };
  345.  
  346. enum JUSTIFY {
  347.     LEFT, CENTRE, RIGHT
  348. };
  349.  
  350. #if !(defined(ATARI)&&defined(__GNUC__)&&defined(_MATH_H)) /* FF's math.h has the type already */
  351. struct cmplx {
  352.     double real, imag;
  353. };
  354. #endif
  355.  
  356.  
  357. struct value {
  358.     enum DATA_TYPES type;
  359.     union {
  360.         int int_val;
  361.         struct cmplx cmplx_val;
  362.     } v;
  363. };
  364.  
  365.  
  366. struct lexical_unit {    /* produced by scanner */
  367.     TBOOLEAN is_token;    /* true if token, false if a value */ 
  368.     struct value l_val;
  369.     int start_index;    /* index of first char in token */
  370.     int length;            /* length of token in chars */
  371. };
  372.  
  373.  
  374. struct ft_entry {        /* standard/internal function table entry */
  375.     char *f_name;        /* pointer to name of this function */
  376.     FUNC_PTR func;        /* address of function to call */
  377. };
  378.  
  379.  
  380. struct udft_entry {                /* user-defined function table entry */
  381.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  382.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  383.     struct at_type *at;            /* pointer to action table to execute */
  384.     char *definition;             /* definition of function as typed */
  385.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  386. };
  387.  
  388.  
  389. struct udvt_entry {            /* user-defined value table entry */
  390.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  391.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  392.     TBOOLEAN udv_undef;        /* true if not defined yet */
  393.     struct value udv_value;    /* value it has */
  394. };
  395.  
  396.  
  397. union argument {            /* p-code argument */
  398.     int j_arg;                /* offset for jump */
  399.     struct value v_arg;        /* constant value */
  400.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  401.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  402. };
  403.  
  404.  
  405. struct at_entry {            /* action table entry */
  406.     enum operators index;    /* index of p-code function */
  407.     union argument arg;
  408. };
  409.  
  410.  
  411. struct at_type {
  412.     int a_count;                /* count of entries in .actions[] */
  413.     struct at_entry actions[MAX_AT_LEN];
  414.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  415. };
  416.  
  417.  
  418. /* Defines the type of a coordinate */
  419. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  420. enum coord_type {
  421.     INRANGE,                /* inside plot boundary */
  422.     OUTRANGE,                /* outside plot boundary, but defined */
  423.     UNDEFINED                /* not defined at all */
  424. };
  425.   
  426. #if defined(MSDOS) || defined(_Windows) 
  427. typedef float coordval;        /* memory is tight on PCs! */
  428. #else
  429. typedef double coordval;
  430. #endif
  431.  
  432. struct coordinate {
  433.     enum coord_type type;    /* see above */
  434.     coordval x, y, z;
  435.     coordval ylow, yhigh;    /* ignored in 3d */
  436. #if (defined(_Windows) && !defined(WIN32)) || (defined(MSDOS) && defined(__TURBOC__))
  437.     char pad[10];        /* pad to 32 byte boundary */
  438. #endif
  439. };
  440.  
  441. struct curve_points {
  442.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  443.     enum PLOT_TYPE plot_type;
  444.     enum PLOT_STYLE plot_style;
  445.     char *title;
  446.     int line_type;
  447.     int point_type;
  448.      int p_max;                    /* how many points are allocated */
  449.     int p_count;                    /* count of points in points */
  450.     struct coordinate GPHUGE *points;
  451. };
  452.  
  453. struct gnuplot_contours {
  454.     struct gnuplot_contours *next;
  455.     struct coordinate GPHUGE *coords;
  456.      char isNewLevel;
  457.      char label[12];
  458.     int num_pts;
  459. };
  460.  
  461. struct iso_curve {
  462.     struct iso_curve *next;
  463.      int p_max;                    /* how many points are allocated */
  464.     int p_count;                    /* count of points in points */
  465.     struct coordinate GPHUGE *points;
  466. };
  467.  
  468. struct surface_points {
  469.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  470.     enum PLOT_TYPE plot_type;
  471.     enum PLOT_STYLE plot_style;
  472.     char *title;
  473.     int line_type;
  474.     int point_type;
  475.     int has_grid_topology;
  476.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  477.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  478.     struct iso_curve *iso_crvs;
  479. };
  480.  
  481. struct TERMENTRY {
  482.     char *name;
  483.     char *description;
  484.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  485.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  486.         put_text,text_angle,justify_text,point,arrow;
  487. };
  488.  
  489. #ifdef _Windows
  490. #define termentry TERMENTRY far
  491. #else
  492. #define termentry TERMENTRY
  493. #endif
  494.  
  495.  
  496. struct text_label {
  497.     struct text_label *next;    /* pointer to next label in linked list */
  498.     int tag;            /* identifies the label */
  499.     double x,y,z;
  500.     enum JUSTIFY pos;
  501.     char text[MAX_LINE_LEN+1];
  502. };
  503.  
  504. struct arrow_def {
  505.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  506.     int tag;            /* identifies the arrow */
  507.     double sx,sy,sz;        /* start position */
  508.     double ex,ey,ez;        /* end position */
  509.     TBOOLEAN head;            /* arrow has a head or not */
  510. };
  511.  
  512. /* Tic-mark labelling definition; see set xtics */
  513. struct ticdef {
  514.     int type;                /* one of three values below */
  515. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  516. #define TIC_SERIES 2        /* user-defined series */
  517. #define TIC_USER 3            /* user-defined points */
  518. #define TIC_MONTH 4        /* print out month names ((mo-1)%12)+1 */
  519. #define TIC_DAY 5        /* print out day of week */
  520.     union {
  521.        struct {            /* for TIC_SERIES */
  522.           double start, incr;
  523.           double end;        /* ymax, if VERYLARGE */
  524.        } series;
  525.        struct ticmark *user;    /* for TIC_USER */
  526.     } def;
  527. };
  528.  
  529. /* Defines one ticmark for TIC_USER style.
  530.  * If label==NULL, the value is printed with the usual format string.
  531.  * else, it is used as the format string (note that it may be a constant
  532.  * string, like "high" or "low").
  533.  */
  534. struct ticmark {
  535.     double position;        /* where on axis is this */
  536.     char *label;            /* optional (format) string label */
  537.     struct ticmark *next;    /* linked list */
  538. };
  539.  
  540. /*
  541.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  542.  
  543.  * printing a status message.
  544.  * SS$_ABORT is the general abort status code.
  545.  from:    Martin Minow
  546.     decvax!minow
  547.  */
  548. #ifdef    vms
  549. #include        <ssdef.h>
  550. #include        <stsdef.h>
  551. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  552. #define    IO_ERROR    SS$_ABORT
  553. #endif /* vms */
  554.  
  555.  
  556. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  557. #define    IO_SUCCESS    0
  558. #endif
  559. #ifndef    IO_ERROR
  560. #define    IO_ERROR    1
  561. #endif
  562.  
  563. /* Some key global variables */
  564. extern TBOOLEAN screen_ok;
  565. extern TBOOLEAN term_init;
  566. extern TBOOLEAN undefined;
  567. extern struct termentry term_tbl[];
  568.  
  569. extern char *alloc();
  570. extern char GPFAR *gpfaralloc();    /* far versions */
  571. extern char GPFAR *gpfarrealloc();
  572. extern void gpfarfree();
  573. /* allocating and managing curve_points structures */
  574. extern struct curve_points *cp_alloc();
  575. extern int cp_extend();
  576. extern int cp_free();
  577. /* allocating and managing surface_points structures */
  578. extern struct surface_points *sp_alloc();
  579. extern int sp_replace();
  580. extern int sp_free();
  581. /* allocating and managing is_curve structures */
  582. extern struct iso_curve *iso_alloc();
  583. extern int iso_extend();
  584. extern int iso_free();
  585.  
  586. /* Windows needs to redefine stdin/stdout functions */
  587. #ifdef _Windows
  588. #include "win/wtext.h"
  589. #endif
  590.